<template>
  <div class="app-container">
    <!-- 列表 -->
    <el-table :data="list" stripe>
      <el-table-column type="index" label="序号" width="60" align="center" />
      <el-table-column prop="lendNo" label="标的编号" width="160" />
      <el-table-column prop="amount" label="标的金额" />
      <el-table-column prop="period" label="投资期数" />
      <el-table-column label="年化利率">
        <template slot-scope="scope">
          <!--{{ scope.row.lendYearRate * 100 }}%-->
          {{ scope.row.lendYearRate }}%
        </template>
      </el-table-column>
      <el-table-column prop="investAmount" label="已投金额" />
      <el-table-column prop="investNum" label="投资人数" />
      <el-table-column prop="publishDate" label="发布时间" width="150" />
      <el-table-column prop="lendStartDate" label="开始日期" />
      <el-table-column prop="lendEndDate" label="结束日期" />
      <el-table-column prop="params.returnMethod" label="还款方式" />
      <el-table-column prop="params.status" label="状态" />
      <el-table-column label="操作" width="150" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini">
            <router-link :to="'/lend/detail/' + scope.row.id">
              查看
            </router-link>
          </el-button>
          <el-button
            v-if="scope.row.status == 1"
            type="warning"
            size="mini"
            @click="makeLoan(scope.row.id)"
          >
            放款
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import api from '@/api/lend'
export default {
  data(){
    return {
      list: []
    }
  },
  created(){
    this.fetchData()
  },
  methods:{
    makeLoan(lendId){
      this.$confirm('即将执行放款操作','放款确认',{
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(()=>{
        api.makeLoan(lendId).then(res=>{
          this.$message.success('放款成功' || res.data.message)
          //刷新数据
          this.fetchData()
        })
      }).catch(()=>{
        this.$message.info('您取消了放款')
      })
    },
    fetchData(){
      api.list().then(res=>{
        this.list = res.data.items
      })
    }
  }
}
</script>
